package com.hangzhou.xyj.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.hangzhou.xyj.ui.fragment.FamousExpertFragment;
import com.hangzhou.xyj.ui.fragment.FamousTeamFragment;
import com.hangzhou.xyj.ui.fragment.HotspotFragment;

/**
 * Created by DT-038 on 2015/12/22.
 * 首页戏台tab切换adapter
 */
public class HomeStageVPAdapter extends FragmentPagerAdapter {
    private final String[] mTitles = {
            "名家",
            "演员",
            "头条",
    };
    private FamousExpertFragment mFamousExpertFragment;
    private FamousTeamFragment mFamousTeamFragment;
    private HotspotFragment mHotspotFragment;

    public HomeStageVPAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                if (mFamousExpertFragment == null) {
                    mFamousExpertFragment = new FamousExpertFragment();
                }
                return mFamousExpertFragment;
            case 1:
                if (mFamousTeamFragment == null) {
                    mFamousTeamFragment = new FamousTeamFragment();
                }
                return mFamousTeamFragment;
            case 2:
            default:
                if (mHotspotFragment == null) {
                    mHotspotFragment = new HotspotFragment();
                }
                return mHotspotFragment;
        }
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }
}
